package com.gouaixin.bee.beeframework2.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;

import com.gouaixin.bee.beeframework2.R;
import com.gouaixin.bee.beeframework2.activity.B6_ziliaoActivity;
import com.gouaixin.bee.beeframework2.adapter.B2_fensiAdapter;
import com.gouaixin.bee.beeframework2.bean.GUANZHU;
import com.gouaixin.bee.beeframework2.bean.ZhenxinhuaFriend;
import com.gouaixin.bee.beeframework2.dao.zhenxinhuaFriendDao;
import com.gouaixin.bee.beeframework2.tool.mLog;
import com.google.gson.Gson;

import java.util.ArrayList;
import java.util.List;


/**
 * Created by Administrator on 2015/3/9.
 */
//我关注的
public class B2_guanzhuBieFragment2 extends Fragment {
    View mainView;

    ListView listView;
//    guanzhubieAdapter adapter;
    ArrayList<GUANZHU> data=new  ArrayList<GUANZHU>();

    B2_fensiAdapter adapter;
    List<ZhenxinhuaFriend> datas=new  ArrayList<ZhenxinhuaFriend>();



//    /**
//     *  在这里实现Fragment数据的缓加载.    
//     */
//    public boolean isVisible;
//
//    public void setUserVisibleHint(boolean isVisibleToUser) {
//        super.setUserVisibleHint(isVisibleToUser);
//        if (getUserVisibleHint()) {
//            isVisible = true;
//            onVisible();
//        } else {
//            isVisible = false;
//            onInvisible();
//        }
//    }
//
//    protected void onVisible() {
//
//        setData();
//
//        setListener();
//
//    }
//
//
//    protected void onInvisible() {
//    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        mainView = inflater.inflate(R.layout.b2_guanzhubie, null);
        adapter=new B2_fensiAdapter(getActivity());

        initView();

        setData();
        setListener();




        return mainView;
    }

    private void setData() {
//        String cid = PreferencesUtils.getString(getActivity(), "cid", "");
//        BaseModel.setCallBackLister(new BaseModel.CallBackLister() {
//            @Override
//            public String onCallBack(String url, String result) {
//                if(url.equals(MyAPI.getguanzhulist)){
//                    if(!result.equals("")){
//                        data=new Gson().fromJson(result, new TypeToken<ArrayList<GUANZHU>>(){}.getType());
//                        mLogUtil.e("解析返回值：" + data.size());
//                        adapter.setData(data);
//                        listView.setAdapter(adapter);
//                    }
//
//                }
//
//                return url;
//            }
//        });
//        RequestParams params = new RequestParams();
//        params.addBodyParameter("cid", cid);
//        BaseModel.post(MyAPI.getguanzhulist, params);

        datas = zhenxinhuaFriendDao.query(getActivity());
        if (datas!=null) {
            adapter.setData(datas);
            listView.setAdapter(adapter);
            adapter.notifyDataSetChanged();

            mLog.e("关注我的datas:" + new Gson().toJson(datas));


        }


    }

    private void setListener() {
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//                AbToastUtil.showToast(getActivity(),"你点击了粉丝："+position+"\tHerId="+datas.get(position).getJid());


                if (datas!=null) {
                    Intent it = new Intent().setClass(getActivity(), B6_ziliaoActivity.class);
                    it.putExtra("HerId",datas.get(position).getJid());
                    startActivity(it);
                }



            }
        });

    }

    private void initView() {
        listView = (ListView) mainView.findViewById(R.id.list);

    }
}
